#include "OutputJavaFile.hpp"
unsigned __int64 Level1::OutputJavaFile::ConstantInformationUTF8::BuildString(const std::u32string& str, ConstantInformationUTF8* ptr)
{
	unsigned __int64 index(0);
	for (auto ch : str)
	{
		if (ch < 128)
			ptr->str[index++] = static_cast<unsigned char>(ch);
		else if (ch < 2048)
		{
			ptr->str[index++] = static_cast<unsigned char>((ch >> 6) | 0xC0);
			ptr->str[index++] = static_cast<unsigned char>(ch & 0x3F) | 0x80;
		}
		else if (ch < 65536)
		{
			ptr->str[index++] = static_cast<unsigned char>((ch >> 12) | 0xE0);
			ptr->str[index++] = static_cast<unsigned char>((ch >> 6) & 0x3F | 0x80);
			ptr->str[index++] = static_cast<unsigned char>(ch & 0x3F) | 0x80;
		}
		else
		{
			ptr->str[index++] = 0xED;
			ptr->str[index++] = static_cast<unsigned char>((ch >> 16) | 0xA0);
			ptr->str[index++] = static_cast<unsigned char>((ch >> 10) & 0x3F | 0x80);
			ptr->str[index++] = 0xED;
			ptr->str[index++] = static_cast<unsigned char>((ch >> 6) & 0x0F | 0xB0);
			ptr->str[index++] = static_cast<unsigned char>(ch & 0x3F | 0x80);
		}
	}
	return index;
}